package com.easy.order.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.Order;
import com.easy.common.service.IOrderService;
import com.easy.common.util.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    IOrderService orderService;

    @GetMapping
    public Result getOrderByOrderNo() {
        Order orderByOrderNo = orderService.getOrderByOrderNo("2025090410001");
        return Result.success(orderByOrderNo);
    }

    @PutMapping
    public Result addOrder(@RequestBody Order order) {
        return Result.success(orderService.addOrder(order));
    }

    @PostMapping
    public Result updateOrder(@RequestBody Order order) {
        return Result.success(orderService.updateOrder(order));
    }

    @DeleteMapping("/{orderNo}")
    public Result deleteOrder(@PathVariable String orderNo){
        int i = orderService.deleteOrder(orderNo);
        if (i == 0)
            return Result.fail(500,"删除失败");
        return Result.success("修改成功");
    }

//    @GetMapping
//    public Result getAll(Order order) {
//        return Result.success(orderService.getAll(order));
//    }

    @GetMapping("/page")
    public Result getPage(Order order, Page<Order> page) {
        IPage<Order> result = orderService.getPage(order, page);
        return Result.success(result);
    }














//    @GlobalTransactional
//    @RequestMapping("/addOrder")
//    public String addOrder() {
//        Goods goodsById = goodsService.getGoodsById(1);
//        goodsById.setId(null);
//        goodsService.addGoods(goodsById);
////        int i=1/0;
//        return "addOrder";
//    }




}
